﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Collections;

public partial class CMS_Admin_MyPublic : System.Web.UI.Page
{
    Usas.Common.Cms.Role ro = new Usas.Common.Cms.Role();
    Usas.Common.Cms.CurrentInfo cinfo = new Usas.Common.Cms.CurrentInfo();
    Usas.BLL.Cms.cmsArticle ar = new Usas.BLL.Cms.cmsArticle();
    Usas.BLL.Cms.AspPager ap = new Usas.BLL.Cms.AspPager();

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            try
            {
                if (Request["page"] == null)
                {
                    Bind(1);
                }
                else
                {
                    Bind(Convert.ToInt32(Request["page"]));
                }
            }
            catch
            {
            }
        }
    }

    public void Bind(int NowPage)
    {

        DataTable dt = null;
        string name = Request["name"] != null ? Server.UrlDecode(Request["name"]) : "";
        string status = Request["status"] != null? Server.UrlDecode(Request["status"].ToString()) :"";
        
        if(name != "")
        {
            txttopic.Text = name;
            name = " and ArtTopic like '%" + name + "%' ";
        }

        if (status != "")
        {
            ddlstatus.SelectedValue = status;
            status = " and (PublishStatus=" + status + ")";
        }

        


        string strWhere = "1=1";
        string CurrentTableWhere = "writer=" + cinfo.GetEmpId() + " and (Isversion=0 or Isversion is null) and ArtFormat != 1 " + name + status;
        int ShowNum = 10;


        string Sortby = "ArtOrder";
        string table = "cmsArticle";
        string where = "artid in (select p_pid from cms_purview_setting where " + strWhere + " and p_table='a')" + " and " + CurrentTableWhere;
        string pk = "ArtId";
        int page = NowPage;
        int num = ShowNum;
        string by = Sortby;
        string cols = "ArtId,TypeId,BorderId,ParentArtId,ArtOrder,ArtDirectory,ArtTopic,ArtKeys,ArtFrom,ArtSummary,ArtFileName,ModfiyTime,hits,Modify,Writer,Auditer,Audit,ArtFormat,Version,CanView,ArtViewPurview,ArtEditPurview,ShowOrder,IsVersion,IsTop,PublishStatus";


        dt = ap.ShowListDesc(table, where, pk, num, page, cols);

        if (dt != null && dt.Rows.Count > 0)
        {
            RptChatList.DataSource = dt;
            RptChatList.DataBind();

            apg.CurrentPageIndex = page;
            apg.PageSize = num;
            apg.RecordCount = ap.ShowListCount(table, where, pk);


        }
        else
        {
            DivContent.InnerHtml = "<div style='text-algin:center'>没有发布内容</div>";
        }

    }



    protected void Search_Click(object sender, EventArgs e)
    {


        string page = Request["page"] == null ? "" : " &page=" + Request["page"].ToString();



        string status = ddlstatus.SelectedValue == "-1" ? "" : " &status=" + Server.UrlEncode(ddlstatus.SelectedValue);
        
        //string name = Request["name"] == null ? "" : " and name=" + Server.UrlDecode(Request["name"].ToString());
        string name = txttopic.Text.Trim().Length <= 0 ? "" : " &name=" + Server.UrlEncode(txttopic.Text.Trim());

        Response.Redirect("MyPublic.aspx?" + page + status + name);
        return;
        Response.Redirect("MyPublic.aspx?page=" + Request["page"].ToString());


        if (Request["page"] != null)
        {
            if (txttopic.Text.Trim().Length <= 0)
            {
                Response.Redirect("MyPublic.aspx?page=" + Request["page"].ToString());
            }
            else
            {
                Response.Redirect("MyPublic.aspx?page=" + Request["page"].ToString() + "&name=" + Server.UrlEncode(txttopic.Text.Trim()));
            }
        }
        else
        {
            if (txttopic.Text.Trim().Length <= 0)
            {
                Response.Redirect("CheckList.aspx");
            }
            else
            {
                Response.Redirect("CheckList.aspx?name=" + Server.UrlEncode(txttopic.Text.Trim()));
            }
        }
    }
    protected void Save_Click(object sender, EventArgs e)
    {
        Response.Redirect(Request.Url.ToString());
    }
    protected void RptChatList_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
        {
            DataRowView drv = (DataRowView)e.Item.DataItem;

            HyperLink hygoto = (HyperLink)e.Item.FindControl("hygoto");
            //hygoto.NavigateUrl = "ViewContent.aspx?id=" + drv["ArtId"].ToString() + "&type=a";

            hygoto.Text = "<img src=\"../images/edit.gif\" border=\"0\" title=\"查看\" /> 查看";
            hygoto.NavigateUrl = "javascript:void(0)";
            hygoto.Attributes.Add("style", " text-decoration:none;");

            hygoto.Attributes.Add("onclick", "javascript:openwin('ViewContent.aspx?id=" + drv["ArtId"].ToString() + "&type=a');return false");


            CMS_Control_RouterBar rb = (CMS_Control_RouterBar)e.Item.FindControl("RouterBar1");
            rb.IntiBarNoHTML(CMS_Control_RouterBar.ShowMode.Article, Convert.ToInt32(drv["ArtId"].ToString()), new ArrayList());
        }
    }
    protected void RptChatList_ItemCommand(object source, RepeaterCommandEventArgs e)
    {

    }
}
